﻿using System;

public class ArrayCalculator
{
    public static void Calculate(int[] array, out int max, out int min, out double average, out int sum)
    {
        //检查数组是否存在数据
        if (array == null || array.Length == 0)
            throw new ArgumentException("数组不能为空或长度为零");

        //初始化赋值
        max = array[0];
        min = array[0];
        sum = 0;

        //遍历数组求最大值、最小值、和
        foreach (int num in array)
        {
            if (num > max) max = num;
            if (num < min) min = num;
            sum += num;
        }

        average = (double)sum / array.Length;
    }

    public static void Main()
    {
        //测试例子
        int[] array = { 1, 2, 3, 4, 5 };
        int max, min, sum;
        double average;

        ArrayCalculator.Calculate(array, out max, out min, out average, out sum);

        Console.WriteLine("最大值：{0}", max);
        Console.WriteLine("最小值：{0}", min);
        Console.WriteLine("平均值：{0}", average);
        Console.WriteLine("总和：{0}", sum);
    }
}

